<!DOCTYPE html>
<html>
<head>

    <%include("/common/header.html",{title:'设置我的资料'}){}%>

</head>
<body>
<div class="x-nav" style="margin: 20px auto auto 15px;">
      <span class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
        <a href="javascript:;">首页</a><span lay-separator="">/</span>
        <a href="javascript:;">系统设置</a><span lay-separator="">/</span>
        <a><cite>APP首页模块二</cite></a>
      </span>
    <!--<a class="layui-btn layui-btn-primary layui-btn-small" style="margin: -5px 14px 0px 0px;float:right;"-->
    <!--href="javascript:location.replace(location.href);" title="刷新">-->
    <!--<i class="layui-icon layui-icon-refresh-3"></i>-->
    <!--</a>-->
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <!--<div class="layui-card-header">用户协议管理</div>-->
                <div class="layui-card-body" >

                    <form action class="layui-form" lay-filter="setmyinfo">

                        <input type="hidden" name="id" id="hid">

                        <div class="layui-form-item">
                            <div style="text-align: center;margin: 0px auto">
                                <h2>添加/更改“模块二”</h2>
                            </div><hr/>

                            <div class="layui-input-block" style="width: 600px;margin: 0px auto">
                                <textarea id="content" type="text"  style="display: none;height: 300px;" name="content" lay-verify="" class="layui-textarea"></textarea>
                            </div>

                            <!--<div class="layui-input-block"style="width: 600px;margin: 0px auto">
                                <textarea style="height: 300px;" type="text" name="content" lay-verify="required" id="content" placeholder="请输入用户协议内容" class="layui-textarea"></textarea>
                            </div>-->
                        </div>

                        <div  style="width: 96px;margin: 0px auto;">
                            <button class="layui-btn" lay-submit="" lay-filter="setmyinfo">添加/更改</button>

                        </div>
                        <div  style="float: right;margin-top: -20px;">
                            <span>发布时间：<span id="addtime" style="font-size: 16px"></span></span>
                        </div>
                    </form>

                </div>
            </div>
        </div>

    </div>
</div>

<%include("/common/foot.html"){}%>

<script>
    layui.config({
        base: 'static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'set','form','jquery','upload','layedit','laydate','table'],function () {
        var update_url='system/block2/updateOrSave.jhtml';
        var findAll_url='system/block2/findAllBlock2.json';
        var form =layui.form;
        var layedit = layui.layedit;
        var index;
        var $ = layui.jquery;

        //富文本编辑器
        layedit = layui.layedit;

        //获取后台数据
        $.ajax({
            url: findAll_url,
            data: {},
            type: "post",
            async : false,
            dataType: "json",
            success: function (ret) {
                for (var i = 0; i < ret.data.length; i++) {
                    $("#content").val(ret.data[i].content);
                    //alert(ret.data[i].addtime);
                    $("#addtime").text(ret.data[i].addtime);
                    $("#hid").val(ret.data[i].id);
                }
            }
        });


        //建立编辑器
        index =layedit.build('content',{
            tool: ['strong','italic','underline','del','|',
                'left', 'center', 'right','|',
                'link','unlink', ],
            //uploadImage: {url: 'banner/upload1.jhtml', type: 'post'},
            height:320
        });

        //提交添加数据
        form.on('submit(setmyinfo)', function(data){
            data.field.content = layedit.getContent(index);
            postUpdate(data);
            return false;
        });

        //ajax提交修改内容
        window.postUpdate = function (data){
            var formData = new FormData();
            // 利用append的内置方式
            formData.append("data", JSON.stringify(data.field));

            $.ajax({
                url: update_url,
                type: "POST",
                data:formData,
                processData: false,
                contentType: false,
                success: function(data){
                    if (data.code == 0) {
                        layer.closeAll();
                        layer.msg(data.msg, {time: 600, icon: 1}, function () {
                            location.replace(location.href);
                        });
                    } else {

                        //layer.msg(data.msg, {icon: 6});
                    }
                    //location.replace(location.href);
                },

                error:function(jqXHR, textStatus, errorThrown){
                    var estr="Page:"+window.location.pathname+",Function:postUpdate()";
                    layer.open({
                        title: "错误信息",
                        area: ['600px', '600px'],
                        type: 2,
                        content: "base/error.jhtml?info="+estr, //
                        btn: ['关闭'] //可以无限个按钮
                    });
                }
            });
        }

    });
</script>
</body>
</html>